asp.net - Modify and redirect for not found URl in web api -


i enabled html5 mode in angular project witch convert url

a: qwe.com/#/products

to

b: qwe.com/products

but problem in case if user trying directly go b, server (web api) catch url , return not found error need way catch not found in server add # sign , redirect new url how should it?

update:

thanks @travis collins

in global.asax

private const string root_document = "/index.html";  protected void application_beginrequest( object sender, eventargs e ) {    string url = request.url.localpath;    if ( !system.io.file.exists( context.server.mappath( url ) ) )        context.rewritepath( root_document ); } 

you need rewrite on server end this. make web server still serve index.html file when request comes in /products or else. in iis example, in web.config:

<system.webserver>   <rewrite>     <rules>        <rule name="main rule" stopprocessing="true">         <match url=".*" />         <conditions logicalgrouping="matchall">           <add input="{request_filename}" matchtype="isfile" negate="true" />                                            <add input="{request_filename}" matchtype="isdirectory" negate="true" />         </conditions>         <action type="rewrite" url="/" />       </rule>     </rules>   </rewrite> </system.webserver> 

lots of other servers explained here: https://github.com/angular-ui/ui-router/wiki/frequently-asked-questions#how-to-configure-your-server-to-work-with-html5mode


Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -