The need is to host a customer ASP.NET control in an ASP.NET MVC application. The custom ASP.NET control that I am trying to host in ASP.NET MVC application has an HttpHandler in it which deals with image rendering.
I have placed the custom ASP.NET control inside a Site.Master page and DataBinding of the custom control is written in the Site.Master.cs page inside an ASP.NET MVC application.
Now the problem that I am facing is that the custom ASP.NET control gets rendered whereas the HttpHandler used by the custom ASP.NET control couldn’t be recognized. Also, I have added the HttpHandler details inside the web.config file as well.
You should not be using server controls or custom user controls in an ASP.NET MVC application. ASP.NET MVC doesn't work with server controls. Server controls rely on ViewState and ASP.NET MVC does not have ViewState.
If you want to serve images you can create an MVC action method that returns a FileResult and then create a partial view that includes an image tag with the src referecing that action method. You can then reuse the partial view in any of your views.
You can also use WebApi instead of an mvc action if you like.
harivenkates...
0 Points
1 Post
Problem in HttpHandler recognization when adding ASP.NET custom control into MVC application.
Aug 07, 2012 02:55 PM|LINK
Hi
The need is to host a customer ASP.NET control in an ASP.NET MVC application. The custom ASP.NET control that I am trying to host in ASP.NET MVC application has an HttpHandler in it which deals with image rendering.
I have placed the custom ASP.NET control inside a Site.Master page and DataBinding of the custom control is written in the Site.Master.cs page inside an ASP.NET MVC application.
Now the problem that I am facing is that the custom ASP.NET control gets rendered whereas the HttpHandler used by the custom ASP.NET control couldn’t be recognized. Also, I have added the HttpHandler details inside the web.config file as well.
[Site.Maser]
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site1.master.cs" Inherits="MVCSample.Views.Shared.Site1" %>
<%@ Register Assembly="XXXX, Version=XXXXX, Culture=neutral, PublicKeyToken=XXXXX"
Namespace="XXXXXX" TagPrefix="cc1" %>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
<cc1:XXXXX ID="XXXXX" runat="server" Height="200px" Width="200px" ClientIDMode="AutoID" />
</asp:ContentPlaceHolder>
[Site.Maser.cs]
namespace MVCSample.Views.Shared
{
public partial class Site1 : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
<Binding code for the control>
}
}
}
}
[web.config]
<httpHandlers>
<add path="XXXX.ashx" verb="*" type="XXXXXXXX"/>
</httpHandlers>
Any help on this would be appreciated.
Thanks in advance.
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Problem in HttpHandler recognization when adding ASP.NET custom control into MVC application.
Aug 07, 2012 05:12 PM|LINK
You should not be using server controls or custom user controls in an ASP.NET MVC application. ASP.NET MVC doesn't work with server controls. Server controls rely on ViewState and ASP.NET MVC does not have ViewState.
If you want to serve images you can create an MVC action method that returns a FileResult and then create a partial view that includes an image tag with the src referecing that action method. You can then reuse the partial view in any of your views.
You can also use WebApi instead of an mvc action if you like.
Blog | Twitter : @Hattan