I am working on an asp.net MVC3 application.
I have a LiveFeedController
with methods that return a list of items based on options that the user selects. It returns a full view or partial view depending on if the request is an ajax request.
For example:
Public Class LiveFeedController
Inherits System.Web.Mvc.Controller
<Authorize(Roles:="CanViewFeed")>
Function Feed(Optional ByVal feedID As Nullable(Of Guid) = Nothing, Optional ByVal itemID As Nullable(Of Guid) = Nothing, Optional ByVal refreshTimer As Double = 0.0) As ActionResult
Dim feedVM As New FeedViewModel
feedVM.SelectedFeedID = feedID
feedVM.SelectedItemID = itemID
feedVM.RefreshTimer = refreshTimer
Return View(feedVM)
End Function
<Authorize(Roles:="CanViewFeed")>
<HttpPost()>
Function Feed(ByVal collection As FormCollection) As ActionResult
Dim feedVM As New FeedViewModel
TryUpdateModel(feedVM , collection)
If Request.IsAjaxRequest Then
Return PartialView("PartialFeed", feedVM)
End If
Return View(feedVM)
End Function
My problem is that if an ajax request is submitted to the HttpPost method, and the user is no longer logged in (so the Authorize fails), the content returned is my logon page specified in the web.config file:
<authentication mode="Forms">
<forms loginUrl="~/Account/LogOn" timeout="2880" />
</authentication>
This is being displayed in a dynamic section of my page/view but it is making the html invalid because the content returned is a full view for the logon page.
I would like too avoid this problem and properly display the content of the log in page. How can I accomplish this?
Thanks,
-Frinny