Subscribe: Personal Site Starter Kit
http://forums.asp.net/rss.aspx?ForumID=1003&PostID=2137748
Added By: Feedage Forager Feedage Grade B rated
Language: English
Tags:
antiforgery  button  data  date  microsoft aspnetcore  new xelement  new  request  runat server  runat  server  text  token  view 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: Personal Site Starter Kit

All Forums



All Forums



Last Build Date: Wed, 21 Feb 2018 23:31:22 -0800

 



Is it safe to use IP 127.0.0.1 while accessing local machine files?

2018-02-21T10:03:15.167-08:00

Is it safe to use IP 127.0.0.1 while accessing local machine files?




Bootstrap/Nav Tabs not working after update

2018-02-21T20:58:06.033-08:00

I am not sure what caused this (I am inclined to blame Team Foundation Server, because I just hate it), but here is what is happening.

We have these tabsets.


 

And these pages

...
...

This seems to comply with the tutorials I am seeing online.

It's important to note that this is happening site-wide, not just on this page.  Also, this worked last week before a particularly fateful TFS Get Latest.

Here is the symptom.

  1. When the second tab is clicked, the page pane blanks, and the second tab does not highlight.
  2. When the first tab is clicked again, it returns to the correct first pane and the first tab remains highlighted.

I figure either some library is not getting loaded, or the matching mechanism from the tabs to the panes has changed somehow.




Add Column Link in gridView

2018-02-20T12:02:17.213-08:00

I’m trying to add the column in gridview datatable at the end. By click the link it will show the detail of the data. My codes as follows

 SqlConnection con = new SqlConnection(strcon);

             SqlCommand cmd = new SqlCommand("Select ID,[Date], [Name] from info order by [Date] desc", con);

            SqlDataAdapter daGrid = new SqlDataAdapter(cmd);

            DataSet ds = new DataSet();

             daGrid.Fill(ds);

            gridiview1.DataSource = ds.Tables[0];

           gridiview1.DataBind();




How can i make my GridView only shows data based on a search field for example my Autogenerated ID

2018-02-22T07:16:02.67-08:00

so I want my GridView only shows data based on my search and there should be edit and delete and update within the gridview itself also I tried by my own but when I link the textbox search that is linked with my database using sqldatasource then link that with the gridview the search works but it will ask me to refresh and then the edit and delete and update will disappear <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EditDelete.aspx.cs" Inherits="test.EditDelete" %>
  

 Create New Records/Print Forms    Search For Records Based on Vendor Name     

Search Records by Date::  
 



webApi in old asp.net website - webforms

2018-02-20T12:25:45.097-08:00

Hello, i have an old web site (not web application project vs) in asp.net 4.0 webforms c#.

i wan't add apicontroller and i create it in app_code (vs ask me before creating, Controller folder is not available), so i add global asax file and in application_start

System.Web.Routing.RouteTable.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional }
);

My controller il TestController public class TestController : ApiController
{
// GET api/
[HttpGet()]
public IEnumerable GetHelloWorld()
{
return new string[] { "value1", "value2" };
}

but in my browser get http://localhost/api/test/get always have 404, and No type was found that matches the controller named

So, my controller always not found, What did I do wrong? 

thx




How to pass Form data and ListBox data to controller through Ajax?

2018-02-08T16:42:12.42-08:00

Hi, can anybody help me to find what is wrong with my this codes for passing form data and Listbox data to controller by ajax? Here is the ajax code: $("#btnGetData").click(function () {                                var button1 = "getdata";                 var listItms = $('#ChooseRight').val();   // this is Lisbox field in Razor view                 var formData = $('#GenForm').serialize();  //the Form ID of razor view                 var wildcardprodtype = $('#WildCardProdType').val();                                $.ajax({                     type: 'POST',                     url: '/Report/LongRunningProcess',  //controller name                                        data: JSON.stringify({                         button: button1,                         viewModel: formData,                         ChooseRight: listItms,                         WildCardProdType: wildcardprodtype                     }),                                   contentType: "application/json; charset=utf-8",                     dataType: "json",                     async: true,                     success: function (data) {                     }                 }); Here is the controller, in debug, I can see the data of "button", WildCardProdType are passed properly, but not the data of viewModel and ChooseRight list. Any reason why? public ActionResult LongRunningProcess(string button, ReportViewModel viewModel, List ChooseRight, string WildCardProdType) {    .... here is the @HtmlBegin form header: @using (Html.BeginForm(null, null, FormMethod.Post, new { id = "GenForm" } )) { By the way, the current razor view use ReportViewModel as this: @model MVCPROD.Models.ViewModels.ReportViewModel [...]



Asyn ConfigureWait Question

2018-02-20T23:50:39.12-08:00

Do I need to set ConfigureWait(true) on every async call if I am waiting for a Loading... panel to work and response back? Or can I just call the first one with a ConfigureAwait(true) and then every other one to the database ConfigureAwait(false)?

Thanks. 




C# - How to find total rows affected when using EventLogReader (eventLogQuery)?

2018-02-22T07:00:08.3-08:00

I'm trying to read eventlogs from a server which has about 100 000 records using class EventLogReader(eventLogQuery).

I'm using pagination and each page will show only 25 records in my screen. So, I will be reading 25 records out of total records for the first page and next 25 records for the second page and so on.

My question is how to get the total records count for the below snippet like total rows affected because of that eventLogQuery applied on full set of events?

EventLogReader reader = new 
EventLogReader(eventLogQuery);
                reader.Seek(SeekOrigin.Begin, filter.PageStart);

eventLogs.TotalLogs = **totalRowsAffected**;                    
EventRecord eventInstance = reader.ReadEvent();

int i = filter.PageSize;
while (eventInstance != null && i-- > 0)
{
 try
 {
  eventLogs.Entries.Add(new EventLogData
  {
   Type = eventInstance.LevelDisplayName,
   Source = eventInstance.ProviderName,
   Time = eventInstance.TimeCreated,
   Category = eventInstance.TaskDisplayName,
   EventId = eventInstance.Id,
   User = eventInstance.UserId != null ? eventInstance.UserId.Value : "",
   Computer = eventInstance.MachineName,
   Message = eventInstance.FormatDescription(),
   FullXml = eventInstance.ToXml()
  });
 }catch{}
eventInstance = reader.ReadEvent();
}
}
return eventLogs;




looking for someone who some experience with the payflow SDK

2018-02-21T23:02:07.43-08:00

I am looking for someone who has some experience with payflow gateway sdk for payflow link to help me getting strated with integration

thx for ur help




Event listener in Web API

2018-02-22T06:22:28.223-08:00

I have a windows project which is using 3 party dlls to communicate. this 3 party dlls are also sending events which is been captured inside the windows project via events& delegates.

Note: the events fired by the 3 party dlls are the UDP packets.

I need to convert this project to asp.net Web API. I have added those dlls in my web api and I am able to communicate to send request and receive response via the dll's. Now, I have to receive the events from those dlls in web api.

Is there anything I can try to make it possible.




scale image based on a frame background

2018-02-08T20:54:33.24-08:00

Hi all,

There are a lot of zoom and crop plugins in jQuery but what I am looking for is bit different.
I am in need to show a frame and user would zoom in/out image till it seems fit in that frame so that every image taken is proper in terms of angle and distance.

For example I want to save image of car in various views like Left side, Right Side and accordingly there would be preset frames which should appear as overlay when image is being uploaded for a particular view and until user sees that image is filling in frame or overlay, he can zoom in or zoom out and once it is in desired view then it should save image as final one.

Can anybody please tell me how to show overlay/frame to help user to upload image.

Thanks
Vinod K.




Entity Framework "Database First" not generating Foreign keys (MYSQL)

2018-02-21T15:03:16.16-08:00

Hi!

my table has some foreign key constraints. except for one constraint all the other relationships are fine.

from MySQL workbench, I tried with reverse engineering to see all the relationships are added. 

in that, it shows all the relationships correctly.

but when it comes to the visual studio it not mapping to the table.




Appropriate Way of Creating a SQL View In ASP Core Code First Approach

2018-02-20T17:49:31.33-08:00

Hi

Googling around led me to deduce that one following the Code First approach can't have a view created for database in the SQL and a model based on the same for an MVC view. The only method I came across was to create a model referring to a similar structured table and having a SQL view with the same structure be created replacing the table so created. In regard of using Code First approach to get an Entity Framework mapped to a view, instead of a table, when an initial migration file was generated, I commented out the portion referring to the said imaginary table, and right at the same position inserted the query as follows:

//Table Part Commented Out
/*migrationBuilder.CreateTable(
    name: "D_XYZ",
    columns: table => new
    {
        ...
    },
    constraints: table =>
    {
        ...
    });*/

//SQL For View Inserted
migrationBuilder.Sql("CREATE VIEW [dbo].[D_XYZ] AS select ...");

However, I find that if I run the Update-Database the said database creates successfully with the required View instead of a table. However, to check it again, I dropped the said database and this time, when I Run the said ASP Core app by F5, the database initialized by it had a Table instead of a View?

  • Why is it so, while I had commented out the relevant portion in the migration file?
  • Isn't the Migration file used upon the launch? or it is based only on the Models as defined?
  • Upon completion of a project and at the time of the deployment, would a manual separate running of the Migration or a Query to drop a Table and replacing it with a View would be required?

Thanks




Update textbox text

2018-02-21T16:16:11.003-08:00

Hello,

I have an asp form that has a grid view with radio buttons. I want to update the text of the textbox every time a new radio button is clicked like a counter but I don't want to refresh the page.

Any ideas/Suggestions?

Thank you




Insert white Spaces in XML to LINQ generated document

2018-02-22T05:23:22.34-08:00

I am using the following code to generate the XML.

 XElement contacts =
new XElement("Contacts",
new XElement("Contact",
new XElement("Name", "Patrick Hines"),
new XElement("Phone", "206-555-0144",
new XAttribute("Type", "Home")),
new XElement("phone", "425-555-0145",
new XAttribute("Type", "Work")),
new XElement("Address",
new XElement("Street1", "123 Main St"),
new XElement("City", "Mercer Island"),
new XElement("State", "WA"),
new XElement("Postal", "68042")
)
));
This gives me



Patrick Hines
206-555-0144
425-555-0145


123 Main St
Mercer Island
WA
68042



but I want to generate an XML with white Spaces/newlines in before few elements. For Eg:
if I want to push few elements to the right like below..



          Patrick Hines
         206-555-0144
         425-555-0145
       


                     123 Main St
                       Mercer Island
                                 WA
                         68042
      


I am reading this generated XML into a tool which needs such weird spacing in XML files else it fails reading XML files.

I am not sure if generating the above XML is possible with LINQ to XML or should I use XMLTextWriter ?




LINQ to retrieve the number of users registered per month

2018-02-21T11:57:43.99-08:00

Hi,

I have a user table, which contains the users registered to an application.

I need to retrieve the list  of number of users registered each month . The month should be taken from the CreatedOn field in the same table.

I need to generate report based on this data. so i need the output as follows

UserCount    Month

2                    Jan

3                   Feb

I am using mvc5 with EF6 to retrieve  the data. How can i retrieve the data in the above format using linq/lambda expression.




How To Change Month And Year To Fromdate And Todate In Sp

2018-02-22T04:27:39.077-08:00

Dear all,

Can somebody help me to revise below original SP where it would display cardno for the month period. What I want is to display cardno by date range Eg, txtLog_date and txtCompleted_date
FYI, asp will call ashx file and from ashx pass the 3 parameter to sp as below

http://172.20.100.12:888/rpt_vehicle.ashx?cardno=0000055799&month=2&year=2018

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

-- Batch submitted through debugger: db-deploy.SQL|6|0|C:\CorpServer\ATTD\Report\db-deploy.SQL

Alter PROC [dbo].[$_Rpt_vehicle]
@Card VARCHAR(16), -- Employee Card No.
@Year INT, -- Trx. Year
@Mnth INT, -- Trx. Month

@txtLog_date datetime, ------ FromDate newly added field passed from asp
@txtCompleted_date datetime ------------ ToDate newly added field passed from asp


AS SET NOCOUNT ON
BEGIN
DECLARE @Temp TABLE ( [Id] INT IDENTITY(1,1), [Date] DATETIME, [WDay] NVARCHAR(100) )
DECLARE @DtFr DATETIME, @DtTo DATETIME

SET @DtFr = CAST(CAST(@Year AS VARCHAR) + '/' + CAST((@Mnth+0) AS VARCHAR) + '/01' AS DATETIME)
SET @DtTo = DATEADD(month, 1,CAST(CAST(@Year AS VARCHAR) + '/' + CAST((@Mnth+0) AS VARCHAR) + '/01' AS DATETIME))

;WITH tData AS
( SELECT @DtFr [Date] UNION ALL SELECT DATEADD(DAY,1,[Date]) FROM tData WHERE DATEADD(DAY,1,[Date]) < @DtTo )
INSERT INTO @Temp ( [Date], [WDay] ) SELECT mt.[Date], DATENAME(WEEKDAY,mt.[Date]) FROM tData mt

SELECT
'',

CardNo [EmplCard], Name [EmplName], [DepartmentDesc] [EmplSrcs], [InOut] [InOutDes],

TrDate [TrnxDate], TrTime [TrnxTmMn], TrController [TrnxTmMx],

''

FROM VW_RPT_van2

WHERE
CardNo = @Card AND YEAR(TrDate) = @Year AND MONTH(TrDate) = @Mnth
GROUP BY
TrDate, [TrDay], TrTime, CardNo, Name, [DepartmentDesc], [InOut] , TrController
END
------------------- end of SP ---------------------------------

Now, my requirement is is to change the parameter type from month(int) and year(int) to txtLog_date(datetime) and txtCompleted_date(datetime)

because I already revised my asp parameter as this http://172.20.100.12:888/rpt_vehicle.ashx?cardno=0000055799&txtLog_Date='2/1/2018'&txtCompleted_Date='2/22/2018'

The problem is that when it goes to above SP, it failed to show data ..

any advice how to revise above SP ?

Thanks a lot,




How to export data right?

2018-01-25T18:42:32.37-08:00

I have a database with some data get by somewhere. 

Now i want to export the data to text files. But there can be many data. it can run many minutes.

  • I want to start export with one API call. In working state, no another call should can start another export. the export should mark each datarow (with subrows) after exporting
  • Another call should ask the export about his state
  • At finisch the export, the export should save an with state and notes in the database 

I have experimented and my actual code is not stable. Sometimes it break with no output or i get "New transaction is not allowed because there are other threads running in the session." Is there someway a tutorial how to build the scenario or any hints for me?




Apparently Random Error: "Antiforgery token validation failed. The antiforgery cookie token and request token do not match."

2018-02-06T14:50:03.457-08:00

Background I have a relatively new ASP.NET Core 2 site. It's running on just one server, and I only restart the site once every few days when I upload an update. About once a day, a user's request fails due to rejection by the anti-forgery system. These are POST requests, and there's nothing particularly special about them. I'm including the anti-forgery value in the POST request, and 99% of the time, they work. The stdout log says, "Antiforgery token validation failed. The antiforgery cookie token and request token do not match." Errors I've included the relevant portions of the stdout log below. info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1] Request starting HTTP/1.1 POST [domain redacted] application/x-www-form-urlencoded 234 info: Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ValidateAntiforgeryTokenAuthorizationFilter[1] Antiforgery token validation failed. The antiforgery cookie token and request token do not match. Microsoft.AspNetCore.Antiforgery.AntiforgeryValidationException: The antiforgery cookie token and request token do not match. at Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery.ValidateTokens(HttpContext httpContext, AntiforgeryTokenSet antiforgeryTokenSet) at Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery.d__9.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ValidateAntiforgeryTokenAuthorizationFilter.d__3.MoveNext() info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[3] Authorization failed for the request at filter 'Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.AutoValidateAntiforgeryTokenAuthorizationFilter'. info: Microsoft.AspNetCore.Mvc.StatusCodeResult[1] Executing HttpStatusCodeResult, setting HTTP status code 400 info: Microsoft.AspNetCore.Mvc.RazorPages.Internal.PageActionInvoker[2] Executed action /Index in 2.6224ms warn: Microsoft.AspNetCore.Antiforgery.Internal.DefaultAntiforgery[1] Antiforgery validation failed with message 'The antiforgery cookie token and request token do not match.'. For requests that result in the above stdout output, IAntiforgery.IsRequestValidAsync agrees by returning false. Here's a reduced example of a failed POST request and the associated cookie. POST: __RequestVerificationToken=CfDJ8MaM8-ULaotKhrvVVKXdGgUxork4jTkt343ArrABhTtbRVKMxPm7suOo6490GWo8QoQmFNt8iL1XjajwYezj_y3exGfXYM8pXgNPjkTuPgG-Hlzdw7Kg_hu_yiPkQo2KKjBZB5NOIWfPqBecVMEsKOQ Cookie: .AspNetCore.Antiforgery.ClRyCRmWApY:CfDJ8MaM8-ULaotKhrvVVKXdGgVKKYfnM3HQVB1OgVz-ty6QaZDh-PDHS5pj7D-dIZRDx85uTCXjdTvV8FoAKLlti4poxLBrzze7dkGCSbWFgWUbr-UDxSyHFgOw2dpV0gvA0M7R39ENzzJiboDv11aUQPM The error message said, "The antiforgery cookie token and request token do not match." The POST and cookie strings are not exact matches, but in my experience, they never are. They look very similar to every other anti-forgery POST and cookie pair I normally see, so I can't deduce what's going wrong here. ASP.NET Core 2 on GitHub I decided to look at the source code of ASP.NET Core 2. I found this file, especially line 145: https://github.com/aspnet/Antiforgery/blob/dev/src/Microsoft.AspNetCore.Antiforgery/Internal/DefaultAntiforgeryTokenGenerator.cs That line gets the message "The antiforgery cookie token and request token do not match." from this file at line 134: [...]



asp label value doesnt set from codebehind

2018-02-21T07:31:38.707-08:00

Hi

I have some buttons in my page , but only 1 that i needed to work fails to set a value in label.text. Kindly please anyone help me , to identify the issue where the label cannot be set from a "btnPrintPDF_Click" button while the other buttons could assign just fine.

.aspx:


onclick="btnSearch_Click"/>
onclick="btnExport_Click"/>




.cs Codebehind

protected void btnPrintPDF_Click(object sender, EventArgs e)
{
lblerror.Text = "btnPrintPDF_Click";


foreach (GridViewRow row in gvContactList.Rows)
{

CheckBox checkbox = (CheckBox)row.FindControl("cbRowSelect");

//Check if the checkbox is checked.
//value in the HtmlInputCheckBox's Value property is set as the //value of the delete command's parameter.
if (checkbox.Checked)
{

string RowID = Convert.ToString(gvContactList.DataKeys[row.RowIndex].Value);

try
{

ReportViewer1.Reset();
ReportViewer1.LocalReport.Dispose();
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.Refresh();

reportGenerate(RowID);

}
catch (Exception ex)
{
string ext;
ext = ex.ToString();
Response.Write("");
}

}}}