Set default webpage for website on Microsoft Windows Azure - asp.net

I recently set up a website on azurewebsites.net.
But when I go to the url http:/website.azurewebsites.net/
it doesn't load.
But when I go to http:/website.azurewebsites.net/home.aspx it loads.
What I want is that
if a user goes to http:/website.azurewebsites.net/ it loads with the home.aspx content or get redirected to http:/website.azurewebsites.net/home.aspx
This doesn't work
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="Default.aspx" />
</files>
</defaultDocument>
</system.webServer>
Sorry here's the actual link http://rathgarfantasyhockey.azurewebsites.net/default.aspx which works fine, but when you go to http://rathgarfantasyhockey.azurewebsites.net HTTP error 404, The resource cannot be found is displayed.
Can anyone help??

According to this blog post: http://blogs.msdn.com/b/cesardelatorre/archive/2010/07/22/how-to-set-a-default-page-to-a-windows-azure-web-role-app-silverlight-asp-net-etc.aspx
<defaultDocument>
<files>
<clear/>
<add value="Default.aspx"/>
</files>
</defaultDocument>
Should Work. Or you could Type to Url map it. To do that check out http://msdn.microsoft.com/en-us/library/cc668201.aspx

If you are using MVC or Web API, add the following line in RegisterRoutes():
routes.IgnoreRoute("");
This solved my problem. Hope it helps you.

If you app is a MVC application, it looks for the default controller instead of default pages.
So you must map a route in RouteConfig. In my case,I wanted to load the site with an index.html page, so I did:
RouteConfig.cs file:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
And in my HomeController, Index Action, write this code:
public ActionResult Index()
{
return Redirect("/index.html");
}
This works fine in Azure with a Shared Site. I hope this will help you.

Do you have a typo?
You have:
<add value="Default.aspx" />
But you said that your "home page" that works is /home.aspx.
If you want for /home.aspx to be displayed when the user goes to http:/website.azurewebsites.net/, then I can think of several ways for you to accomplish that.
Since you have Default.aspx as your defaultDocument, you can rename home.aspx to Default.aspx and when someone goes to http:/website.azurewebsites.net/ the contents of Default.aspx will be displayed.
If you need to keep home.aspx named as home.aspx for some reason, then as you requested if you want for http:/website.azurewebsites.net/ to redirect to /home.aspx then create a file called Default.aspx in the root directory and edit it to contain Response.Redirect("home.aspx", false);. A complete example for this type of page is available at http://msdn.microsoft.com/en-us/library/a8wa7sdt(v=vs.80).aspx.
Update:
Try adding enabled="true" to your defaultDocument XML tag. See the example below from http://www.iis.net/ConfigReference/system.webServer/defaultDocument
<system.webServer>
<defaultDocument enabled="true">
<files>
<add value="home.html" />
</files>
</defaultDocument>
</system.webServer>

Related

How can we allow dots in ASP.NET MVC urls?

I have a website developed in MVC 5 that perform search in inventory and the url is like this
http://localhost:56099/search/SQUARE
This url works, it redirects to Search controller and Index action with search query as SQUARE and gives the correct result. But, if I enter 2 dots as a search query it just takes me to my root page. The url will be like this
http://localhost:56099/search/..
it's strange because same thing works when passing single dot or multiple dots, so I can't find any technical reason why it is getting neglected.
I have done following things in Web.Config:
<modules runAllManagedModulesForAllRequests="true"> for accepting others characters also in search query.
relaxedUrlToFileSystemMapping="true"
But no success and I can't find any real reason for this weird behaviour. Any advice.
you should register the search route in your "RouteConfig.cs" file
routes.MapRoute(
"SearchRoute",
"Search/{*pathinfo}",
new { controller = "Search", action = "ActionName"});
You have the problem with .., because .. in your case is detected as relative URL, which indicates moving up to the parent directory(or root in your case), essentially stripping off everything up to the previous slash in the the Base URI.
UrlRoutingHandler in web.config should help you.
<system.webServer>
<handlers>
<add name="UrlRoutingHandler"
type="System.Web.Routing.UrlRoutingHandler,
System.Web, Version=4.0.0.0,
Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a"
path="/Search/*"
verb="GET"/>
</handlers>
</system.webServer>
Then every URL starting with /Search will be considered as MVC URL.
Also you could try:
<system.webServer>
<security>
<requestFiltering allowDoubleEscaping="true" />
</security>
</system.webServer>

Authorize() functionality is not working on /Account/Register when published

I do want to have a [Authorize()] function on my AccountControllers Register function. I simply do not want anyone to Register new accounts on my site.
//[AllowAnonymous]
[Authorize(Roles="Admin")]
public ActionResult Register()
{
return View();
}
This works perfectly when testing on localhost but fails on my Azure-hosted site.
The code is perfectly the same on localhost as Published.
What can be the fault here? Im guessing that the code isn't beeing run propperly.
Result on Localhost: http://i.imgur.com/aqFPlHZ.png (Correct)
Result on Azure: http://i.imgur.com/gjc9Dz2.png (Faulty (No Autorization))
EDIT:
Maybe this line in the web.config file is mucking it up?
<system.web>
<authentication mode="None" />
</system.web>
<system.webServer>
<modules>
<remove name="FormsAuthenticationModule" />
</modules>
</system.webServer>

ASP.net MVC4 WebApi route with file-name in it

I'm trying to get the following (and similar) urls to work in my ASP.net MVC4/WebApi project:
http://127.0.0.1:81/api/nav/SpotiFire/SpotiFire.dll
The route responsible for this url looks like this:
config.Routes.MapHttpRoute(
name: "Nav",
routeTemplate: "api/nav/{project}/{assembly}/{namespace}/{type}/{member}",
defaults: new { controller = "Nav", assembly = RouteParameter.Optional, #namespace = RouteParameter.Optional, type = RouteParameter.Optional, member = RouteParameter.Optional }
);
It works just fine if I remove the . in the file-name, or if I add a slash behind the URL, but that also means I can't use the Url.Route-methods etc. The error I get is a generic 404-error (image below).
I've tried adding <httpRuntime targetFramework="4.5" relaxedUrlToFileSystemMapping="true" /> to my web.config, and I've also tried adding
<compilation debug="true" targetFramework="4.5">
<buildProviders>
<remove extension=".dll"/>
<remove extension=".exe"/>
</buildProviders>
</compilation>
And none of it seems to work. So my question is basically, how can I get this URL to work, and map correctly?
You could add the following handler to the <handlers> section of your <system.webServer>:
<add
name="ManagedDllExtension"
path="api/nav/*/*.dll"
verb="GET"
type="System.Web.Handlers.TransferRequestHandler"
preCondition="integratedMode,runtimeVersionv4.0"
/>
This will make all requests containing .dll be served through the managed pipeline. Also notice how I have limited them only to the GET verb to limit the performance impact.
Found it. What's needed is this (and maybe some of the things I've added above in the original post):
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
My trade off was to append /end to the end of route. .'s are ignored before the last /.
The equivalent URL would be http://127.0.0.1:81/api/nav/SpotiFire/SpotiFire.dll/end.
The benefit being that you don't get a performance hit on your assets.

ASP.NET url routing, default path

I expected this would also map the default homepage as in http://localhost/ but it is not hit.
RouteTable.Routes.Add(new Route("{Keyword}", new HomeHandler()));
Question is of course why not? I would like to map the root to some other page.
I haven't tried this yet but try removing the default document from IIS's configuration. For IIS 7 this setting is in web.config:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
</files>
</defaultDocument>
</system.webServer>
</configuration>
The answer is somewhat complex. It was on IIS6 and we had to add a specific property. I cannot really remember what we did back then but you can google it, that's how I found it.

Diagnosing 404 errors on IIS 7 and ASP.NET MVC

I have an mvc app developed and tested with Cassini. Deployed to my site on GoDaddy, and the default page comes up fine. Click to log in, and I get a 404.
I'm running under IIS 7 there, so this is unexpected. My routes are pretty plain:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Public", action = "Index", id = "" }
);
routes.MapRoute(
"Report1",
"Report/{action}/{start}/{end}",
new { controller = "Report", action = "Index" }
);
routes.MapRoute(
"Report2",
"Report/{action}/{start}/{end}/{idList}",
new { controller = "Report", action = "Index" }
);
Any idea what might be going on or how I can troubleshoot this?
Are you running in IIS7 integrated mode?
Classic mode of IIS7 does not automatically map extensionless URLs to ASP.NET (much like IIS6).
Also make sure your Web.config <system.webServer> tag is configured correctly.
Don't use runAllManagedModulesForAllRequests. You want to let IIS handle resources such as images.
<system.webServer> <!-- Rather do NOT use this -->
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
Instead add the MVC routing module
<system.webServer>
<modules>
<remove name="UrlRoutingModule-4.0" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
</modules>
</system.webServer>
Tried everything, I had to set my web config like this, to make it work.
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I had the same problem, I uploaded the controller, web.config and other classes but I forgot to upload the bin folder.
After I uploaded the bin folder, it worked!

Resources