Get URL information in Startup

2019-09-06 06:04发布

问题:

In an asp.net MVC 5 project I'm using a katana owin based middlewere to handle the authentication. Inside the Start.cs file I have the Startup class with the Configuration method. Is there a way to get the full URL of the request inside the Configuration method? I need to get the last part of it to be stored in a cookie

public void Configuration(IAppBuilder app) {
     app.UseCookieAuthentication(new CookieAuthenticationOptions { ... }
     // something here to get the full URL

     // other authentication code here
}

回答1:

Startup runs outside of the request-cycle. In fact, it only runs once, and then multiple successive URLs can be serviced before it ever runs again (when AppPool recycles, server restarts, etc.)

Long and short, even if you could access the URL, it wouldn't do you any good because it would simply be the first random URL that was accessed, which may or may not be applicable to whatever you're trying to do here.