Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x

ASP.NET

124K

Solutions

28K

Contributors

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications

Share tech news, updates, or what's on your mind.

Sign up to Post

I have an ASP.Net MVC web application. I have several views and controllers. How do you change what controller a view is tied too? For example, I created a view that referenced code in the HomeController. I created a new controller to house that code only, but I can't get the view to use the new controller instead of the HomeController. I hope that makes sense. Thanks for any help.
0
Free Tool: Site Down Detector
LVL 11
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

How to bind existing crystal report file (report.prt)  to report viewer in asp.net
thanks in advance
0
Hi,
I cannot show the message prompt properly, by the following. Why?

function showMsg0() {
    $.message({
        title: '信息',
        content: 'new或NEW是保护字,不可以选为名字简称!',
        buttons: {
            OK: {
                text: 'OK',
                btnClass: 'btn-green',
                keys: ['enter'],
                action: function () {
                    //$.alert('You clicked OK!');
                }
            },
        }
    });
    return false;
};
...
        protected void userabbr_post_change(object sender, EventArgs e)
        {
            if (tb_userabbr.Text.ToUpper() == "NEW")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "showMsg0()", true);
                tb_userabbr.Text = "";
                return;
            }
        }

Open in new window

0
Hello,
I'm trying to change the height and width of some divs, at runtime, but I haven't had much luck so far.

this my source code

 <div id="divImgContainer" style="height: auto; width: 1000px; overflow-y: scroll; display: inline" runat="server">


           <div id="divImg" style="height: 900px; width: 640px; overflow: auto; float: left;" runat="server">

               <asp:UpdatePanel runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional" ID="upnlMainImage">
                   <ContentTemplate>
                       <asp:Image runat="server" ID="img"
                           ImageUrl=""
                           Height="900px" Width="640px" BorderStyle="Solid" BorderWidth="2px" BorderColor="Red"></asp:Image>
                   </ContentTemplate>
               </asp:UpdatePanel>
           </div>

           <div id="divResult" style="float: left;" runat="server">
               <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="upnlTicks" ChildrenAsTriggers="False">
                   <ContentTemplate>
                       <asp:Panel ID="pnlResult" runat="server" Height="900px" GroupingText="Mark Here" Width="320px">
                           <asp:Label ID="lblResults" runat="server" Text=""></asp:Label>
                           <asp:Repeater ID="rptResults" runat="server" OnItemCommand="rptResults_ItemCommand" OnItemDataBound="rptResults_ItemDataBound">
                               <ItemTemplate>
                            

Open in new window

0
Hi, I'm changing the class at runtime of a table (tblzoom) which is inside a repeater. However the changes are not kept after postbacks.
 <div id="divImgContainer" style="height: auto; width: 1000px; overflow-y: scroll; display: inline">

           <div id="divImg" style="height: 900px; width: 640px; overflow: auto; float: left;">

               <asp:UpdatePanel runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional" ID="upnlMainImage">
                   <ContentTemplate>
                       <asp:Image runat="server" ID="img"
                           ImageUrl=""
                           Height="900px" Width="640px" BorderStyle="Solid" BorderWidth="2px" BorderColor="Red"></asp:Image>
                   </ContentTemplate>
               </asp:UpdatePanel>
           </div>

           <div id="divResult style="float: left;">
               <asp:UpdatePanel runat="server" UpdateMode="Conditional" ID="upnlResults" ChildrenAsTriggers="False">
                   <ContentTemplate>
                       <asp:Panel ID="pnlResult" runat="server" Height="900px" GroupingText="Mark Here" Width="320px">
                           <asp:Label ID="lblResults" runat="server" Text=""></asp:Label>
                           <asp:Repeater ID="rptResults" runat="server" OnItemCommand="rptResults_ItemCommand" OnItemDataBound="rptResults_ItemDataBound">
                               <ItemTemplate>
                                   <table class="nozoom" id="tblzoom" 

Open in new window

0
I am trying to follow some instructions on how to send an email with sendgrid but I cant get it to work.

I have setup an azure account and got an api key. Then I cant get it to work to send the mail.  This is the code where it should be include the right stuff.

In my web.config I have added the api key. SO what should go into the

   
 public class EmailService : IIdentityMessageService
    {
        public Task SendAsync(IdentityMessage message)
        {

                    
        // Plug in your email service here to send an email.
        return Task.FromResult(0);
    }

Open in new window

IdentityConfig.cs
0
With inspiration from https://ppolyzos.com/2016/09/09/asp-net-core-render-view-to-string/ I tried to make an service to render Razor pages to a string.

It seems like page.ViewContext.View is empty and results in a nullreferenceexception. How do i fix this?

var result = await _pageRenderService.RenderPageToStringAsync("Index", viewModel);

Open in new window


The service:
   public interface IPageRenderService
    {
        Task<string> RenderPageToStringAsync(string pageName, object model);
    }
 
    public class PageRenderService : IPageRenderService
    {
        private readonly IRazorViewEngine _razorViewEngine;
        private readonly ITempDataProvider _tempDataProvider;
        private readonly IServiceProvider _serviceProvider;
		private readonly IHttpContextAccessor _httpContext;
		private readonly IActionContextAccessor _actionContext;
 
        public PageRenderService(
			IRazorViewEngine razorViewEngine,
            ITempDataProvider tempDataProvider,
            IServiceProvider serviceProvider,
			IHttpContextAccessor httpContext,
			IActionContextAccessor actionContext
			)
        {
            _razorViewEngine = razorViewEngine;
            _tempDataProvider = tempDataProvider;
            _serviceProvider = serviceProvider;
			_httpContext = httpContext;
			_actionContext = actionContext;
        }
 
		public async Task<string> RenderPageToStringAsync(string pageName, object model)
		{
			var tempData = new 

Open in new window

0
Dear Experts,
Please suggest how to set tab indexing for asp .net input controls in asp.net
0
seeing weird characters from webresponse for bootstrap contents. results expected as this image expected.png, but all i see is below image
result.png
0
good afternoon,
I was wondering if it is posible to use operators like OR/AND as follow in asp.net

 if (_context.User.Any(ac => ac.Id.Equals(23) && ac.Active.Equals(1)))

Open in new window


or what is the right way of doing something similar to that.

I appreciate your help thanks.
0
Hire Technology Freelancers with Gigs
LVL 11
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

After my category drop down list is selected, it is supposed to show the sub categories of that particular category. However there is an error now!
Below is the code, the commented codes are what worked initially, however now i have to use BllSubCategory, which caused the error to occur
     protected void ddlCategory_SelectedIndexChanged(object sender, EventArgs e)
        {
            int MainCategoryID = Convert.ToInt32(ddlCategory.SelectedItem.Value);
            BllSubCategory subCat = new BllSubCategory();
            DataSet ds = subCat.GetSubCatByCatName();
            ddlSubCategory.DataSource = ds;
            ddlSubCategory.DataTextField = "SubCatName";
            ddlSubCategory.DataValueField = "SubCatID";
            ddlSubCategory.DataBind();
            ddlSubCategory.Items.Insert(0, new ListItem("-Select-", "0"));
            ddlSubCategory.Enabled = true;
            /*  int MainCategoryID = Convert.ToInt32(ddlCategory.SelectedItem.Value);
             *  using (SqlConnection con = new SqlConnection(CS))
              {
                  SqlCommand cmd = new SqlCommand("select * from tblSubCategories where MainCatID='" + ddlCategory.SelectedItem.Value + "'", con);
                  con.Open();
                  SqlDataAdapter sda = new SqlDataAdapter(cmd);
                  DataTable dt = new DataTable();
                  sda.Fill(dt);

                  if (dt.Rows.Count != 0)
                  {
                      

Open in new window

0
I need help with my ASP.NET MVC application hosted on iis. The application loses connection to MYSQL database after sometime and requires me to restart mysql service then it continues to connect.
0
say, I have controller method and a corresponding view (see below).

once I load the view, I have a self invoking JavaScript function, that calls the same controller method.
code below, shows the get request, when I test this, I get the value of 1 in the id parameter of my ProcessData method.
in Get request, the data is passed in the query string, which is mapped to my parameter name by ASP.NET ( I guess by the process of model binding). I understand this part.

My question is, if i wanted to do a post request and send a XML data over to the same controller method, how can I achieve this.

In a post request, how do we read data in the controller?

controller -
public ActionResult ProcessData(string id) {          
      return View();
}

view -

@{
    ViewBag.Title = "test";
}

<h2>test</h2>

@section scripts {
    <script type="text/javascript">
        (function () {
            $.ajax({
                type: "Get",
                url: '@Url.Action( "ProcessData", "Test")',
                contentType: "application/xml; charset=utf-8",
                data: {id : 1},              
                success: successFunc,
                error: errorFunc
            });
            function successFunc(data, status) {
                alert('success');
            }
            function errorFunc() {
                alert('error');
            }
    })();
    </script>
}
0
What are some possible reasons that a grid would lose its paging header? I know that's a very broad question. The details that I can give are that the pager template is there when the page loads, but upon a new data bind that is successful the pager template is gone. It does re-appear if I do a sort on any of the columns but that's not how it is supposed to work. Its as if it loses its understanding that it needs to show the pager template after a new datasource has been bound to it? I'm looking for some suggestions of things / properties that I can check to see what would cause this?
0
How to get Google Chrome to behave like IE when it comes to single sign on and ASP.NET applications. We use SSO for our internal applications (VB.NET)  and works great when using IE  however, we have users who prefer Chrome. Is there a way to get Chrome to behave like IE.  

Has anyone got this to work?

Thanks
0
Hi,

I have a very simple code to login on my asp.net site.

  Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
        Dim authorized As Boolean = Membership.ValidateUser(txtUserName.Text, txtPassword.Text)

        If authorized = True Then
            'lblError.Visible = False
            If Roles.IsUserInRole(txtUserName.Text, "ARole") Then
                FormsAuthentication.SetAuthCookie(txtUserName.Text, False)

                Response.Redirect("~/start")
            Else

                PanelError.Visible = True
                lblError.Text = "test."
                authorized = False
            End If

        Else
            PanelError.Style("display") = "block"
            lblError.Text = "text"
        End If
    End Sub

Open in new window


In web.config it looks like this:
  <authentication mode="Forms">
      <forms cookieless="UseCookies" defaultUrl="~/Default.aspx" domain="" enableCrossAppRedirects="false" loginUrl="~/Login" name=".ASPXAUTH" path="/" protection="All" requireSSL="false" slidingExpiration="true" timeout="1440" />
    </authentication>

Open in new window


When the login button is clicked the user is correctly authorized (authorized becomes true) and  FormsAuthentication.SetAuthCookie(txtUserName.Text, False) is executed, but when I use the below code to check if the user is authenicated, authorized is false.

Dim authorized As Boolean = System.Web.HttpContext.Current.User.Identity.IsAuthenticated

            If authorized = True Then

                LoggedIn.Visible = True
                LoggedOut.Visible = False

                'lblName.Text = Profile.FirstName & " " & Profile.LastName
            Else
                LoggedIn.Visible = False
                LoggedOut.Visible = True
            End If

Open in new window


What have I forgotten?

Peter
0
my C# asp.net solution support localization from database, when i call localization class ("Local Resources") its return the string correct in < placeholder>.
but if i call  localization class ("Local Resources") in text=" ". between double quotation. return no result
the code as shown in attached file
viber-image2.jpg
0
I have a viewmodel with a property called Date.  It is a string.  When I use it in a Detail view it shows correctly ( MM/dd/yyyy ).  When I use it in an Edit view it adds the time to the date ( MM/dd/yyyy hh/mm/ss am/pm).  How can I get it to show correctly as just a date?

in viewmodel :  public string Date { get; set; }
in detail view :   @Html.ValueFor(model => model.Date)  // shows correctly  MM/dd/yyyy
in edit view    :   @Html.EditorFor(model => model.Date, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly" } })  // shows as M/d/yyyy + time
0
I have read everything I can get my hands on about ViewState but can't seem to figure out what I'm doing wrong.

In a sub routine that first and foremost fills a grid, I set the value of two controls and then save those to view state:

                    ViewState.Item("SortKey") = SortKey.Value
                    ViewState.Item("RecId") = RecId.Value

I'm using ViewState because I can't seem to get the control values to persist.

On Page_Load I try to retrieve those values into the controls:
            SortKey.Value = ViewState.Item("SortKey")
            RecId.Value = ViewState.Item("RecId")

This does not work.

What am I missing?


Thanks
0
Industry Leaders: We Want Your Opinion!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

I saved my images into bytes in project B to show it in project A.
I did this to try to get the image from the particular id to show, problem is 1.image does not show , 2.it only shows image from EImage01Byte and i need to show the image from EImage0Byte when i click next
<div class="carousel-inner" role="listbox">
      <asp:Repeater ID="rptrImages" runat="server">
          <ItemTemplate>
    <div class="item <%# GetActiveClass(Container.ItemIndex) %>">
       <img src="<%#Eval("EID") %>/<%# "data:image;base64," + Convert.ToBase64String((byte[]) Eval("EImage01Byte")) %>"></img>
  </div>  
              </ItemTemplate>
          </asp:Repeater>
  </div>

Open in new window

Then i did this. Now, all the images in EImage01Byte regardless of the id, so thats a problem, also i need the second image
 <div class="carousel-inner" role="listbox">
      <asp:Repeater ID="rptrImages" runat="server">
          <ItemTemplate>
    <div class="item <%# GetActiveClass(Container.ItemIndex) %>">
       <img src="<%# "data:image;base64," + Convert.ToBase64String((byte[]) Eval("EImage01Byte")) %>"></img>
    </div>  
              </ItemTemplate>
          </asp:Repeater>
  </div>

Open in new window

my code behind is like this !!
 BllCompEventCatalog eve = new BllCompEventCatalog();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindEventImages();
            }
        }
        private void BindEventImages()
        {
            Int64 EID = Convert.ToInt64(Request.QueryString["EID"]);
            DataTable ds = eve.getEventAll();
            rptrImages.DataSource = ds;
            rptrImages.DataBind();
        }
        protected string GetActiveClass(int ItemIndex)
        {
            if (ItemIndex == 0)
            {
                return "active";
            }
            else
            {
                return "";
            }
        }

Open in new window

0
OWA stopped working.

The only error I have in Event viewer is the following:

Log Name:      Application
Source:        ASP.NET 2.0.50727.0
Date:          04-01-2018 11:45:13
Event ID:      1310
Task Category: Web Event
Level:         Warning
Keywords:      Classic
User:          N/A
Computer:      SERVER-CR.rp-sroc.local
Description:
Event code: 3008
Event message: A configuration error has occurred.
Event time: 04-01-2018 11:45:13
Event time (UTC): 04-01-2018 11:45:13
Event ID: 19f3c753447c413d9472b773800071ee
Event sequence: 1
Event occurrence: 1
Event detail code: 0
 
Application information:
    Application domain: /LM/W3SVC/1/ROOT/owa-4-131595399127484622
    Trust level: Full
    Application Virtual Path: /owa
    Application Path: C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\owa\
    Machine name: SERVER-CR
 
Process information:
    Process ID: 1104
    Process name: w3wp.exe
    Account name: NT AUTHORITY\SYSTEM
 
Exception information:
    Exception type: HttpException
    Exception message: Could not load file or assembly 'Microsoft.Exchange.Data.Directory, Version=14.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified. (C:\Program Files\Microsoft\Exchange Server\V14\ClientAccess\owa\web.config line 77)
 
Request information:
    Request URL: https://10.0.0.10:443/owa/auth/error.aspx?aspxerrorpath=/owa/ 
    …
0
Hello,

I have an asp.net application. Basically, it is an intranet application that runs in the cloud.  When crawled by web crawlers, crawl the site, they trip many errors.. usually timeouts, NullReferences, etc.

The applictaion is designed to fire off an email when an exception occurs.  Normally, this is a good thing because I am aware of an exception before I get a help ticket.  But errors tripped by crawlers fill my inbox.

I have used a robots.txt and Google and the legitimate players play by the robot rules. But some more nefarious players do not.

I have black listed some URLS but this only works if the ips are static.  Most of the time there are multiple ip addresses.

Any help or ideas are appreciated.

Vince



Thank

Vince

But some crawlers ignore the robot.txt and crawl the site anyway
0
I had this question after viewing Call Oracle Stored Proc from C# that returns RefCursor.

I have a store procedure like this :
PROCEDURE PRC_ABCD_GETALL (resultset_out OUT TYPES.cursorType)
AS
BEGIN
OPEN
resultset_out FOR SELECT * FROM ABCD;
END PRC_ABCD_GETALL;

and this procedure is in package and the package is like this

create or replace
PACKAGE        V4_EVT_PKG_ABCD_GENERAL
AS

   PROCEDURE PRC_ABCD_GETALL (resultset_out OUT TYPES.cursorType);

END V4_EVT_PKG_ABCD_GENERAL;

and the oracle data provider was system.data.oracleClient and I used this code
public static IEnumerable<PortalList> GetAll()
{
Database db = DatabaseFactory.CreateDatabase();
DbCommand objComm = db.GetStoredProcCommand("package_name.sp", new object[1]);          
var result = new List<PortalList>();        
using (IDataReader rdr = db.ExecuteReader(objComm)){            
while (rdr.Read()){                  
result.Add(Construct(rdr));              
}          
}        
return result;
}
and now i found out that system.data.oracleClient is depricated and i want to use Oracle.DataAccess.Client as data provider
I wrote C# code for this but I am facing some errors like wrong number or types of arguments in call to 'PRC_ABCD_GETALL'
in this function PortalListRepository.GetAll();

private static IEnumerable<PortalList> GetAll(bool …
0
Today I have a application that was made using webforms and I need to migrate to ASP.NET CORE.

This application uses Crystal Reports to generate many reports in PDF format.

I need a solution to migrate this reports, I intent to migrate this solution to a Linux server, then if I can migrate this reports to a solution that run in linux is better.

I've tried iTextsharp, but this don't work in ASP.NET CORE with Linux.
0
when i  implement swagger in my web api, i am getting like below. i want "startDateTime" and "endDateTime" without "z". like ""2018-01-02T19:07:13.594" (without z)

{
  "centerCode": "string",
  "locationType": "string",
  "subject": "string",
  "body": "string",
  "location": "string",
  "startDateTime": "2018-01-02T19:07:13.594Z",
  "endDateTime": "2018-01-02T19:07:13.594Z"
   
}
my model is like below
public class mymodelclass
    {
       public string CenterCode { get; set; }

        public string LocationType { get; set; }

        public string Subject { get; set; }
              public string Body { get; set; }
           public string Location { get; set; }
       
        public DateTime? StartDateTime { get; set; }
     
     
        public DateTime? EndDateTime { get; set; }
       

    }
where should i specify pattern or format for datetime for swagger example to show datetime format like ""2018-01-02T19:07:13.594"(without 'Z').
0

ASP.NET

124K

Solutions

28K

Contributors

The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications