Pergunta

I'm building an asp.net web application that allows users to manage their person account(s) information. Users will have a single web user account, but in some cases it may be associated with multiple accounts at different store locations. So in order for a user to manage their account, I first need them to select the location they want to manage their account for.

This application is a class library that runs within a larger web site, it doesn't define the entire web site. I have a centralized method called GetCurrentStore() that will return the store if a selection exists in Session. If one is not selected, is Response.Redirect([Store Selection Page URL], true) the best way to handle getting one? I know this method throws an exception so it is a somewhat expensive mechanism, but I'm not sure I know of any alternatives that will prevent further processing of the response.

Foi útil?

Solução

is Response.Redirect([Store Selection Page URL], true) the best way to handle getting one?

"Best" is somewhat subjective and very context-dependent, but some observations:

  • By accessing Session from your Class Library, you're increasing coupling (it needs to be called within the context of an HTTP Request, which, among other undesirable traits, makes it less testable). I'd get the name or id of the current store location in the UI tier, and pass it to the class library.

  • If you need to redirect the user to another page, the overhead of throwing an exception is probably negligible. But again, the class library is probably not the best place to do this: you should check if the current store location is in Session in the UI tier, and do the redirect there.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top