Upon reading multiple forums with (kinda) the same issue, but none of those suggested answers fixing my problem, I ended up with my own post.
As the title says, I am having problems with firing my application (on localhost for testing) using Identity authentication.
The error I keep getting:
HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.
Detailed Error Information:
Module
IIS Web Core
Notification
MapRequestHandler
Handler
StaticFile
Error Code
0x80070002
Requested URL
http://localhost:xxxx/auth/login?ReturnUrl=%2F
Physical Path
c:\users\xxxx\documents\visual studio 2015\Projects\MyProject\MyProject\auth\login
Logon Method
Anonymous
Logon User
Anonymous
Request Tracing Directory
C:\Users\xxxx\Documents\IISExpress\TraceLogFiles\MyProject
The code I used is as follows:
The startup class in the App_Start folder
public class Startup
{
public void Configuration(IAppBuilder app)
{
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "ApplicationCookie",
LoginPath = new PathString("/auth/login")
});
}
}
The FilterConfig class also in the App_Start folder:
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new AuthorizeAttribute());
}
}
The registerFilters in the Global.asax
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
}
The controller is Called Auth (AuthController) with the actionresult
Login (and added the view for it). Nothing special here since I was already getting the error.
In the web.config I added the line in appSettings:
<add key="owin:AppStartup" value="MyProject.App_Start.Startup"/>
I have no clue what I am doing wrong, perhaps some IIS config that is wrong? Or is it really the path that is giving the errors?
These are the things (taken from several other posts) which I have already tried
<add key="autoFormsAuthentication" value="false" />
and <add key="enableSimpleMembership" value="false"/>
to the WebConfig file. After some meddling and looking at other Identity posts I found out that the error message I am getting is because I have set the URL in RouteConfig to empty.
I had it like this:
routes.MapRoute(
name: "Default",
url: "",
defaults: new { controller = "StartWeb", action = "Index", id = UrlParameter.Optional }
);
while it should be like this:
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "StartWeb", action = "Index", id = UrlParameter.Optional }
);
When changing it back to the default the error was gone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.